#include "server.hpp"

std::string host = "127.0.0.1";
std::string username = "root";
std::string password = "qwertyuiop0723.";
std::string dbname = "gobang";
uint16_t port = 3306;

void mysql_test()
{
    // std::string sql = "insert stu values (10,'李华',18,82.5,98.5,86);";
    std::string sql = "insert user values (100,'小明',20,92.5,87.5,90);";
    MYSQL *mysql = mysql_util::mysql_create(host, username, password, dbname, port);
    mysql_util::mysql_exec(mysql, sql);
    mysql_util::mysql_destory(mysql);
}

void json_test()
{
    Json::Value root;
    std::string body;
    root["姓名"] = "小明";
    root["年龄"] = 18;
    root["成绩"].append(92);
    root["成绩"].append(90);
    root["成绩"].append(83);
    json_util::serialize(root, body);
    std::cout << body.c_str() << std::endl;

    Json::Value val;
    json_util::deserialize(body, val);
    std::cout << "姓名: " << val["姓名"].asString() << std::endl;
    std::cout << "年龄: " << val["年龄"].asInt() << std::endl;
    int sz = val["成绩"].size();
    for (int i = 0; i < sz; i++)
    {
        std::cout << "成绩: " << val["成绩"][i].asFloat() << std::endl;
    }
}

void str_test()
{
    std::string str = ",...,,123,234,,,,,345,,,,";
    std::vector<std::string> arry;
    string_util::split(str, ",", arry);
    for (auto s : arry)
    {
        DLOG("%s", s.c_str());
    }
}
void file_test()
{
    std::string filename = "./makefile";
    std::string body;
    file_util::read(filename, body);

    std::cout << body << std::endl;
}

void db_test()
{
    Json::Value val;
    val["username"] = "xiaoming";
    val["password"] = "qwer123456";
    user_table ut(host, username, password, dbname, port);
    ut.login(val);
    std::string body;
    json_util::serialize(val, body);
    std::cout << body << std::endl;
}

void online_test()
{
    online_manager om;
    wsserver_t::connection_ptr conn;
    uint64_t uid = 2;
    om.enter_game_room(uid, conn);
    if (om.is_in_game_room(uid))
        DLOG("in game room");
    else
        DLOG("not in game room");
    if (om.is_in_game_hall(uid))
        DLOG("in game hall");
    else
        DLOG("not in game hall");
}
int main()
{
    // mysql_test();
    // json_test();
    // str_test();
    // file_test();
    // db_test();

    // online_test();
    // onlie_manager om;
    // user_table ut(host, username, password, dbname, port);
    // room r(2, &ut, &om);
    // room_manager rm(&ut, &om);
    // matcher_manager mm(&rm, &ut, &om);
    // return 0;

    // gobang_server _server(host, username, password, dbname, port);
    // _server.start(8080);
    // return 0;

    gobang_server server(host, username, password, dbname);
    server.start(8080);

    return 0;
}